#include "Dictionary.h"

Dictionary::Dictionary(const string filename){
	cout << "Reading dictionary " << filename;

	filebuf f;
	if( f.open(filename.c_str(), ios_base::in) == 0 ){
		cout << "- error!\n";
		return;
	}
	
	istream from(&f);
	char c;
	bool isString = false;
	long v = 0;
	string s = "";
	while( from.get(c) ){
		if( c == '\t' )
			isString = true;
		else if( c == '\n' ){
			isString = false;
			insert( Dictionary::value_type(s, v));
			v = 0;
			s = "";
		}
		else if( isString ){
			if( c >= '0' && c <= '9' )
				v = v * 10 + c - '0';
		}
		else
			s += c;	
	}
	if( s != "" ){
		insert( Dictionary::value_type(s, v) );
	}
	f.close();
	cout << " - finished!\n";
}
